package org.nlp2rdf.navigator.component.resource.maps;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.apache.log4j.Logger;
import org.nlp2rdf.navigator.client.exception.NKEQueryException;
import org.nlp2rdf.navigator.component.Component;

public abstract class AbstractMap extends Component implements IMap {
	private static final Logger logger = Logger.getLogger(AbstractMap.class);

	protected Map<String, String> myMap = new HashMap<String, String>();

	public Map<String, String> getMap(Set<String> keys) throws NKEQueryException {
		check();
		if(myMap.size()==0){
			logger.warn("No data in map "+getClass().getCanonicalName()+", bean might not be initialized");
		}
		return filterMap(keys, myMap);
	}

	protected static Map<String, String> filterMap(Set<String> keys, Map<String, String> map) {

		Map<String, String> ret = new HashMap<String, String>();
		try {
			for (String key : keys) {
				String tmp = map.get(key);
				if (tmp != null) {
					ret.put(key, tmp);
				}
			}
		} catch (Exception e) {
			logger.error("inserted map was strange", e);
		}

		return ret;
	}

}
